home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_a_d / aspdll.zip / CDLLSPEC.TXT < prev    next >
Text File  |  1992-07-02  |  5KB  |  157 lines

  1. Writing Dynamic Link Libraries
  2. for
  3. The Windows ASPECT Script Language
  4.  
  5. C Language Interface Specification
  6.  
  7. Introduction
  8.  
  9.     PROCOMM PLUS for Windows implements a powerful scripting language called the 
  10. Windows ASPECT Script Language (ASPECT).  One of ASPECT's great strengths is the ability 
  11. to call functions embedded in Dynamic Link Libraries (or DLLs) written and compiled outside of 
  12. ASPECT.  This paper focuses on the writing of DLLs for ASPECT in the C language.
  13.  
  14. ASPECT to DLL Parameter Sequence
  15.  
  16.     ASPECT generates a standard parameter block for every DLL call that it makes.  This 
  17. standard parameter block has five parameters, listed in order below.  When writing a DLL to be 
  18. called from ASPECT, every exported function that is to be accessible from within ASPECT 
  19. should declare exactly these number and types of parameters:
  20.  
  21.     1.    [HWND] - a handle to the PROCOMM PLUS for Windows main window.
  22.     2.    [HANDLE] - a handle to the instance of PROCOMM PLUS for Windows that 
  23. made the DLL call.
  24.     3.    [void far * far *] - a far array of far pointers to the data elements listed as 
  25. parameters on the ASPECT script line that called the DLL function.
  26.     4.    [LPBYTE] - a far array of bytes.  Byte N of this array describes the type of 
  27. element N stored in the array of data elements (i.e. parameter 3).  The range of 
  28. values in this array follows:
  29.  
  30.             Byte
  31.             Value    Meaning                         
  32.               0    nth element is an ASPECT string
  33.               1    nth element is an ASPECT integer
  34.               2    nth element is an ASPECT long
  35.               3    nth element is an ASPECT float
  36.  
  37.     5.    [int] - an integer containing the count of parameters provided on the ASPECT 
  38. script line calling the DLL function.
  39.  
  40.  
  41. An Example
  42.  
  43.     Below is the code for a DLL with a function that generates a random number.  Under a 
  44. PASCAL style, stack-based parameter passing scheme, a variable number of parameters is not 
  45. normally possible; however, ASPECT provides an array-based parameter passing scheme as 
  46. described by the parameter block above.  To demonstrate the ability to pass a variable number of 
  47. parameters, the DLL function listed below makes certain assumptions about the provided 
  48. parameters based on the number of parameters that are available:
  49.  
  50.     1.    If two parameters are passed to the DLL function:
  51.         a.    the first parameter holds a number for seeding the random-number 
  52. generator.
  53.         c.    the second parameter will hold the return value (i.e. the random number).
  54.  
  55.     2.    If one parameter is passed to the DLL function:
  56.         a.    the DLL function should seed the random number generator using the 
  57. GetCurrentTime() function (from the Windows API).
  58.         c.    the single parameter will hold the return value (i.e. the random number).
  59.  
  60. Here is the code for the DLL.  This is RANDINT.C:
  61.  
  62. #include <windows.h>
  63. #include <stdlib.h>
  64.  
  65. #define IntegerType 1
  66.  
  67. int FAR PASCAL LibMain( HANDLE, WORD, WORD, LPSTR );
  68. int FAR PASCAL RandomInt( HWND, HANDLE, void far * far *, LPBYTE, int );
  69. int FAR PASCAL WEP( int );
  70.  
  71. HANDLE hInst;
  72.  
  73. int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSeg, WORD cbHeapSize,
  74.   LPSTR lpszCmdLine )
  75. {
  76.   if (cbHeapSize)
  77.     UnlockData(0);    /* make the data segment moveable */
  78.   hInst = hInstance;
  79.   return(TRUE);
  80. }
  81.  
  82. int FAR PASCAL RandomInt( HWND PWWnd, HANDLE PWInst,
  83.   void far * far *vdatptr, LPBYTE vtypeptr, int argcnt )
  84. {
  85.   if ( argcnt < 1 )                     /* at least one argument? */
  86.     return( FALSE );                    /* if not, return FAILURE */
  87.   if ( vtypeptr[0] != IntegerType )     /* is first arg an integer? */
  88.     return( FALSE );                    /* if not, return FAILURE */
  89.   if ( argcnt > 1 ) {                   /* more arguments? */
  90.     if ( vtypeptr[1] != IntegerType )   /* is second arg an integer? */
  91.       return( FALSE );                  /* if not, return FAILURE */
  92.     srand( *(int far *)vdatptr[0] );    /* seed the generator with arg */
  93.     *(int far *)vdatptr[1] = rand();    /* get a random number */
  94.   }
  95.   else {
  96.     srand( (unsigned)GetCurrentTime() );/* seed the generator with time */
  97.     *(int far *)vdatptr[0] = rand();    /* get a random number */
  98.   }
  99.   return( TRUE );                       /* return SUCCESS to ASPECT */
  100. }
  101.  
  102. int FAR PASCAL WEP( int bSystemExit )
  103. {
  104.   return(TRUE);
  105. }
  106.  
  107. Here is the project definition file.  This is RANDINT.DEF:
  108.  
  109. LIBRARY RandInt
  110. CODE MOVEABLE DISCARDABLE
  111. DATA SINGLE MOVEABLE
  112. HEAPSIZE 2048
  113. EXPORTS
  114.   WEP        @1
  115.   RandomInt  @2
  116.  
  117. Here is an ASPECT script using the DLL.  This is RANDINT.WAS:
  118.  
  119. ;ASPECT script demonstrating RANDINT.DLL
  120. integer hdll, rNum
  121. proc cleanup
  122.   dllfree hdll
  123.   exit
  124. endproc
  125.  
  126. proc main
  127. string DLLPATH = "C:\PROWIN\ASPECT\RANDINT.DLL" ;path to the DLL
  128.  
  129.   when userexit call cleanup              ;point to cleanup routine
  130.   dllload DLLPATH hdll                    ;load the DLL
  131.   if (failure)
  132.     usermsg "dllload failed"
  133.     exit
  134.   endif
  135.  
  136.   ;generate a random number letting the DLL use system time as seed
  137.   dllcall hdll "RandomInt" rNum
  138.   if (failure)
  139.     usermsg "RandomInt call with system time seed failed"
  140.     cleanup()
  141.   else
  142.     usermsg "RandomInt with system time seed returned %d" rNum
  143.   endif
  144.  
  145.   ;generate a random number with the seed 65
  146.   dllcall hdll "RandomInt" 65 rNum
  147.   if (failure)
  148.     usermsg "RandomInt call with seed 65 failed"
  149.     cleanup()
  150.   else
  151.     usermsg "RandomInt with seed 65 returned %d" rNum
  152.   endif
  153.  
  154.   cleanup()
  155. endproc
  156.  
  157.